import { Document, Schema, model } from 'mongoose'

interface IRechargeRecord extends Document {
  userId: string
  amount: number
  orderId: string
  status: 'pending' | 'success' | 'failed'
  paymentMethod: 'wechat' | 'alipay' | 'qq'
  transactionId?: string
  createdAt: Date
  updatedAt: Date
}

const RechargeRecordSchema = new Schema<IRechargeRecord>({
  userId: { type: String, required: true },
  amount: { type: Number, required: true },
  orderId: { type: String, required: true, unique: true },
  status: {
    type: String,
    enum: ['pending', 'success', 'failed'],
    default: 'pending',
  },
  paymentMethod: {
    type: String,
    enum: ['wechat', 'alipay', 'qq'],
    required: true,
  },
  transactionId: String,
  createdAt: { type: Date, default: Date.now },
  updatedAt: { type: Date, default: Date.now },
})

export { IRechargeRecord, RechargeRecordSchema }
export const RechargeRecord = model<IRechargeRecord>('RechargeRecord', RechargeRecordSchema)
